package com.hjq.demo.yuliao.activity

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.hjq.demo.R
import com.hjq.demo.app.vb.AppVbActivity
import com.hjq.demo.databinding.ActivityAboutUsBinding
import com.hjq.demo.databinding.ActivityFeedbackBinding
import com.hjq.demo.http.model.HttpData
import com.hjq.demo.yuliao.api.FeedbackApi
import com.hjq.http.EasyHttp
import com.hjq.http.listener.HttpCallback

class FeedBackActivity : AppVbActivity<ActivityFeedbackBinding>() {

    companion object {

        private const val INTENT_KEY_INFO: String = "info"

        fun start(context: Context, info: String) {
            val intent = Intent(context, FeedBackActivity::class.java)
            intent.putExtra(INTENT_KEY_INFO, info)
            context.startActivity(intent)
        }
    }

    override fun initView() {
        setOnClickListener(binding.sbCommit)
    }

    override fun initData() {

    }

    override fun onClick(view: View) {
        super.onClick(view)
        if (view == binding.sbCommit) {
            if (binding.setFeedback.text.toString().trim() == "") {
                toast("反馈内容不能为空")
                return
            }

            EasyHttp.post(this)
                .api(FeedbackApi().apply {
                    opinion = binding.setFeedback.text.toString()
                })
                .request(object : HttpCallback<HttpData<Void>>(this) {
                    override fun onSucceed(result: HttpData<Void>?) {
                        toast(result?.getMessage())
                        finish()
                    }
                })
        }
    }
}